package com.whf.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2018/7/16 0016.
 */
@Component
public class WeChatMpConfig {
    @Autowired
    private WeChatConfig weChatConfig;
    @Bean
    public WxMpService wxMpService(){
        //配置文件
        WxMpService wxMpService=new WxMpServiceImpl();
        //配置文件从wxMpConfigStorage()中获取
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }
    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpInMemoryConfigStorage wxMpConfigStorage=new WxMpInMemoryConfigStorage();
        //获取配置文件中的参数
        wxMpConfigStorage.setAppId(weChatConfig.getMpAppId());
        wxMpConfigStorage.setSecret(weChatConfig.getMpAppSecret());
        return wxMpConfigStorage;
    }
}
